import choco.kernel.solver.ContradictionException;
import choco.kernel.solver.constraints.integer.AbstractLargeIntSConstraint;
import choco.kernel.solver.variables.integer.IntDomainVar;


public class SoftLeq extends AbstractLargeIntSConstraint {
	
	IntDomainVar x, y, cost;
	
	public SoftLeq(IntDomainVar[] vars) {
		super(vars);
		x = vars[0];
		y = vars[1];
		cost = vars[2];
	}

	@Override
	public void propagate() throws ContradictionException {
		if(x.getDomainSize()==0 || y.getDomainSize() == 0 ||cost.getDomainSize()==0 ) fail();
		y.setInf(x.getInf()-cost.getSup());
		x.setSup(y.getSup()+cost.getSup());
		if(x.getSup()<=y.getInf()) cost.setVal(0);
		else if (x.getInf()>y.getSup()) {
			cost.setSup(x.getSup() - y.getInf() );
			cost.setInf(x.getInf() - y.getSup() );
		}
	}
	
	@Override
	public boolean isSatisfied() {
		// TODO Auto-generated method stub
		return super.isSatisfied();
	}

}
